import xmlrpclib
from service.exception import *

class RfileTask():
    """Remote file tranfer class """
    def __init__(self,address,port,arg=None):
        self.address=address
        self.port=port
        self.file=arg[0]
        print "Init Rfile Task ",address,port,self.file

    def start(self):
        try:
            f=open(self.file,'r')
        except IOError:
            print "Can not open file",self.file
            raise RfileNoFileError(self.file)
        text=f.read()
        callback= "http://"+self.address+":"+str(self.port)
        server=xmlrpclib.ServerProxy(callback)
        server.recv(text)
        return 0



